home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-04 | 5.1 KB | 230 lines | [TEXT/MMCC] |
- /*****
- * CNeoBenchApp.cp
- *
- * Application methods for a typical application.
- *
- * Copyright © 1992-1993 NeoLogic Systems. All rights reserved.
- *
- *****/
-
- #include "NeoTypes.h"
- #include <stdlib.h>
- #include <Timer.h>
- #include "UDesktop.h"
- #include "UMemoryMgr.h"
- #include "UPowerTools.h"
- #include "LGrowZone.h"
- #include "LList.h"
- #include "CNeoWindow.h"
- #include "CNeoBenchApp.h"
- #include "CNeoBenchDoc.h"
- #include CNeoDatabaseNativeH
- #include "CFiller.h"
- #include CNeoMetaClassH
- #ifdef qNeoThreads
- #include <LThread.h>
- #include CNeoThreadNativeH
- #endif
-
- #include "CIDIndex.h"
-
- extern OSType gSignature;
-
- int main(void)
- {
- CNeoBenchApp * app;
-
- InitializeHeap(4);
- InitializeToolbox();
- new LGrowZone(20000);
-
- app = new CNeoBenchApp();
- app->Run();
- delete app;
-
- return 0;
- }
-
- /***
- * CNeoBenchApp
- *
- * Initialize the application. Your initialization method should
- * at least call the inherited method. If your application class
- * defines its own instance variables or global variables, this
- * is a good place to initialize them.
- *
- ***/
- CNeoBenchApp::CNeoBenchApp(void)
- : CNeoAppRoot(kNeoBenchSig, kNeoBenchFileType)
- {
- long index;
- long delay = 0;
- TMTask timer;
-
- #ifdef qNeoThreads
- new CBenchThread(nil, kNeoCoopThread, nil, kNeoDefaultStackSize, CBenchThread::threadOption_Main);
- #endif
-
- FFileType = kNeoBenchFileType;
-
- // Add CFiller class to the metaclass table
- new CNeoMetaClass(kFillerID, kNeoPersistID, kFillerName, CFiller::New);
- // meta->setKey(kNeoSecondaryIndex, kIDIndexID);
-
- // // Add CIDINdex class to the metaclass table
- // meta = new CNeoMetaClass(kIDIndexID, kNeoNullClassID, "\pCIDIndex", CIDIndex::New, CIDIndex::KeyManager);
-
- // Bound the default size of the NeoAccess object cache to be 3/4 of free memory
- CNeoPersist::FCacheSize = ((FreeMem() / 4) * 3);
- // CNeoPersist::FCacheSize = (FreeMem() / 4);
-
- // Just to make sure that we get more random results.
- srand((unsigned int)clock());
-
- // measure Time Manager overhead
- timer.tmAddr = NULL;
- timer.tmCount = 0;
- timer.tmWakeUp = 0;
- timer.tmReserved = 0;
-
- for (index = 0; index < 100; index++) {
- InsTime((QElemPtr)&timer);
- PrimeTime((QElemPtr)&timer, k30MicroMinutes);
- RmvTime((QElemPtr)&timer);
-
- if (timer.tmCount > 0)
- // milliseconds
- delay += -(k30MicroMinutes + timer.tmCount * 1000);
- else
- // negated microseconds
- delay += -(k30MicroMinutes - timer.tmCount);
- }
-
- // compute average overhead
- gLoopOverhead = delay / 100;
- }
-
- CNeoBenchApp::~CNeoBenchApp(void)
- {
- #ifdef qNeoThreads
- // LThread::ExitThreads();
- #endif
- }
-
- /***
- * createDocument
- *
- * The user chose New from the File menu.
- * In this method, you need to create a document and send it
- * a newFile message.
- *
- ***/
- CNeoDoc *CNeoBenchApp::createDocument(void)
- {
- CNeoBenchDoc * document = nil;
-
- NEOTRY {
- /**
- ** Create your document.
- **
- **/
- document = new CNeoBenchDoc(FALSE, TRUE, FALSE);
- NeoFailNil(document);
- document->SetSuperCommander(this);
-
- /**
- ** Send the document a NewFile() message.
- ** The document will open a window, and
- ** set up the heart of the application.
- **
- **/
- document->newDatabase();
- }
- NEOCATCH {
- /*
- * This exception handler gets executed if a failure occurred
- * anywhere within the scope of the TRY block above. Since
- * this indicates that a new doc could not be created, we
- * check if an object had been allocated and if it has, send
- * it a unrefer message. The exception will propagate up to
- * CSwitchboard's exception handler, which handles displaying
- * an error alert.
- */
-
- if (document) {
- delete document;
- document = nil;
- }
- }
- NEOENDTRY;
-
- return document;
- }
-
- /***
- * OpenDocument
- *
- * The user chose Open… from the File menu.
- * In this method you need to create a document
- * and send it an OpenFile() message.
- *
- * The macSFReply is a good SFReply record that contains
- * the name and vRefNum of the file the user chose to
- * open.
- *
- ***/
-
- void CNeoBenchApp::OpenDocument(FSSpec *aSpec)
- {
- Boolean remote;
- CNeoBenchDoc * document = nil;
-
- #ifdef qNeoShare
- remote = fOpeningRemote;
- #else
- remote = FALSE;
- #endif
-
- VOLATILE(document);
-
- NEOTRY {
- // Our parent will check to see if this is a document we have already opened.
- // If we find the file already open by the app, then fDocument will refer to it.
- // If the file is opened but not by this app, then the parent will signal a failure.
- inherited::OpenDocument(aSpec);
- if (fDocument)
- return;
-
- /**
- ** Create your document.
- **
- **/
- document = new CNeoBenchDoc(TRUE, FALSE, remote);
- NeoFailNil(document);
- document->SetSuperCommander(this);
-
- /**
- ** Send the document an OpenFile() message.
- ** The document will open a window, open
- ** the file specified in the macSFReply record,
- ** and display it in its window.
- **
- **/
- document->openFile(aSpec);
- }
- NEOCATCH {
- /*
- * This exception handler gets executed if a failure occurred
- * anywhere within the scope of the TRY block above. Since
- * this indicates that the document could not be opened, we
- * send it a unrefer message. The exception will propagate up to
- * CSwitchboard's exception handler, which handles displaying
- * an error alert.
- */
- if (document)
- delete document;
- }
- NEOENDTRY;
- }
-
-